home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / CPOPUPME / STRINGUT.C < prev    next >
C/C++ Source or Header  |  1989-08-19  |  2KB  |  58 lines

  1. #include "defs.h"
  2. #include "StringUtil.h"
  3.  
  4. /*****************************************************************************/
  5. void EllipseString( Str255 s, Int16 width) 
  6. {
  7. /*  
  8.     if the string fits inside the given number of pixels, fine -- do nothing
  9.     and return.
  10.     
  11.     if not, return a string that does fit, with ellipses representing the 
  12.     deleted characters.  ellipses are generated by pressing option-semicolon.
  13. */
  14.     Int16 len;
  15.     
  16.     len = FitText( (Ptr)&s[1], s[0], width);
  17.     
  18.     if (len < s[0])    /* string was trimmed */
  19.     {
  20.         s[0] = '╔';    /* last char is ellipse */
  21.     }
  22.         
  23. }    /* EllipseString */
  24. /*****************************************************************************/
  25. Int16 FitText( register Ptr text, register Int16 length, register Int16 width)
  26. /*
  27.     calculate how much of text will fit into width.
  28.     Ptr - points to text
  29.     length - desired length of text
  30.     width - available width in pixels
  31.     returns number of chars that will fit
  32. */
  33. {    register Int16 currWidth;
  34.  
  35.     do
  36.     {
  37.         currWidth = TextWidth( text, 0, length);
  38.         if (currWidth <= width) break;
  39.     }
  40.     while (--length > 0);
  41.     
  42.     return length;
  43.  
  44. }    /* FitText */
  45. /*****************************************************************************/
  46. Int16 toupper(Int16 c)
  47. {
  48.     return (((c >= 'a') && (c <= 'z')) ? (c ^ 0x20) : c);
  49.     
  50. }    /* toupper */
  51. /*****************************************************************************/
  52. Int16 tolower(Int16 c)
  53. {
  54.     return (((c >= 'A') && (c <= 'Z')) ? (c ^ 0x20) : c);
  55.     
  56. }    /* tolower */
  57. /*****************************************************************************/
  58.